package org.yawnage.framework.server 
{
	import flash.utils.Dictionary;
	import org.yawnage.base.BaseKeyMapper;
	import org.yawnage.interfaces.framework.IPublisher;
	import org.yawnage.interfaces.framework.IServiceLayer;
	import org.yawnage.interfaces.framework.IServiceMap;
	 /**
	  * <p>//TODO:To be written</p>
	  * @author Berry Jordaan
	  * @date 2011/09/06 09:55 AM
	  * @copyright  Copyright © Berry/James 2011
	  * @version 1.0.0.0
	  * @description
	  * @history Berry Jordaan on 2011/09/06 09:55 AM: Created
	  */
	public class ServiceMap extends BaseKeyMapper implements IServiceMap
	{

		//************** Enums **************

		//************** Public *************
		
		//************** Private ************
		
		//************** protected **********
		protected var _publisherName:String;
		
		/**
		 * Constructor
		 */
		public function ServiceMap()
		{
			super();
			setClassDescription("org.yawnage.framework.server.ServiceMap");
			
		}
		
		/**
		 * useless comment here!
		 */
		override public function dispose():void 
		{
			super.dispose();
		}
		
		/* INTERFACE org.yawnage.base.interfaces.framework.IServiceMap */
		
		public function registerService(publisherP:IPublisher, serviceNameP:String):void 
		{
			addObject(new ServiceLayer(publisherP, serviceNameP));
		}
		
		public function unRegisterService(name:String):void 
		{
			removeObject(name);
		}
		
		public function unRegisterAll():void 
		{
			unRegisterAll();
		}
		
		public function getService(serviceName:String):IServiceLayer 
		{
			return IServiceLayer(getObjectbyKey(serviceName));
		}
		
		public function printServices():void 
		{
			if (_mapperList.length == 0) {
				_trace("NOTE: No services registered.","test", 0xFF00FF);
			}
			
			_trace("* Services for ["+toString()+"] *","test", 0xFF00FF);
			for each(var ser:IServiceLayer in _mapper) 
			{
				_trace("   SERVICE_NAME:"+ser.key+"  INTERNAL_ID:"+ser.internalID+" PUBLISHER:"+_publisherName+" - "+ser.publisherService,"test", 0xFF00FF);
			}
		}
		
		public function get registeredServices():Number 
		{
			return _mapperList.length;
		}
		
		public function serviceList():Dictionary 
		{
			return _mapper;
		}
		
		public function isService(serviceName:String):Boolean 
		{
			return hasObject(serviceName);
		}
		
	}
}